const DRAFT_KEY_PREFIX = "chat_draft_";

export default {
  data() {
    return {
      draftContent: "",
    };
  },
  methods: {
    $loadDraft(chatId) {
      const key = `${DRAFT_KEY_PREFIX}${chatId}`;
      const saved = window.localStorage.getItem(key);
      this.draftContent = saved || "";
      return this.draftContent;
    },
    $saveDraft(chatId, content) {
      const key = `${DRAFT_KEY_PREFIX}${chatId}`;
      const value = typeof content === "string" ? content : (this.draftContent || "");
      window.localStorage.setItem(key, value);
      this.draftContent = value;
    },
    $clearDraft(chatId) {
      const key = `${DRAFT_KEY_PREFIX}${chatId}`;
      window.localStorage.removeItem(key);
      this.draftContent = "";
    },
  },
};
